const { defineConfig } = require("@vue/cli-service");
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const PrerenderSPAPlugin = require("prerender-spa-plugin-next");
const path = require("path");
module.exports = defineConfig({
  configureWebpack: {
    plugins: [
      new UglifyJsPlugin({
        uglifyOptions: {
          output: {
            comments: false, // 去掉注释
          },
          warnings: false,
          compress: {
            drop_console: true,
            drop_debugger: false,
            pure_funcs: ["console.log"], //移除console
          },
        },
        sourceMap: false,
        parallel: true,
      }),
      new PrerenderSPAPlugin({
        staticDir: path.join(__dirname, "/dist"), //打包的路径
        routes: [
          "/",
          "/about",
        ], //需要预渲染的url
        rendererOptions: {
          inject: { foo: "bar" },
          headless: true, //这个时需要的，不然打包的html没有预渲染
          renderAfterDocumentEvent: "render-event",
        },
        renderAfterTime: 5000
      })
    ],
  },
  devServer: {
    proxy: { //配置跨域
      '/api': {
        target: 'http://127.0.0.1:8080', //填写请求的目标地址
        changOrigin: true, //允许跨域
        pathRewrite: {
          '^/api': '' //请求的时候使用这个api就可以
        }
      }
    }
  }
})
